﻿Public Class ImporterObserRec

    Dim db As New Connexion
    Dim action As String
    Dim Entrer, Entrer2 As String
    Dim TextBoxID As String
    Public idRec As Integer
    Public databaseName As String
    Private Sub ImporterObserRec_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Entrer = ""
        DataGridView1.MultiSelect = False
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridView1.ReadOnly = True
        Entrer2 = ""
        DataGridView2.MultiSelect = False
        DataGridView2.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridView2.ReadOnly = True


        majourOrigine()
        majourDest()

    End Sub



    Private Sub majourOrigine()
        Try
            db.myReq = "SELECT * FROM  [dbo].[FloFauAuteur]"
            db.Connecter(databaseName)
            Me.DataGridView1.Rows.Clear()
            While db.rdr.Read()
                DataGridView1.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(2), db.rdr(3), db.rdr(4), db.rdr(5))
            End While
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub

    Private Sub majourDest()
        Try
            db.myReq = "SELECT * FROM  [dbo].[GroupeAuteur] W INNER JOIN  [SILM].[dbo].[FloFauAuteur] S ON W.Id_Obs=S.Id_Obs where [Id_Rel]='" & idRec & "'"
            db.Connecter(databaseName)
            Me.DataGridView1.Rows.Clear()
            While db.rdr.Read()
                DataGridView2.Rows.Add(db.rdr(0), db.rdr(1), db.rdr(3), db.rdr(4), db.rdr(5), db.rdr(6))
            End While
            db.Disconnecter()

        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Try
            Entrer = ""

            db.myReq = " INSERT INTO  [dbo].[GroupeAuteur] ([Id_Obs],[Id_Rel]) VALUES('" & Me.DataGridView1.SelectedCells(0).Value & "','" & idRec & "')"
            MsgBox(db.myReq)

            db.Connecter(databaseName)
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
        majourDest()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Entrer = ""

            db.myReq = " ELETE FROM  [dbo].[GroupeAuteur] WHERE [Id_Obs] ='" & Me.DataGridView1.SelectedCells(0).Value & "' and [Id_Rel]='" & idRec & "')"
            MsgBox(db.myReq)
            db.Connecter(databaseName)
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
        majourDest()
    End Sub
End Class